<?php
	include_once 'metier/pictogram.dao.mysql.php';
	include_once 'metier/pictogram.class.php';
        
	$db = new myPDO();

        $tmpId = $_POST['id_picto'];
	$tmpNom = utf8_encode($_POST['nom_picto']);
	$tmpTexte = utf8_encode($_POST['text_picto']);
        
        $extension = substr($_FILES["path_img_picto"]["name"], strrpos($_FILES["path_img_picto"]["name"], '.')+1);
        $tmpimage = utf8_encode($_POST['nom_picto']).'.'.utf8_encode($_POST['text_picto']).'.'.$extension;
        $extension2 = substr($_FILES["path_sound_picto"]["name"], strrpos($_FILES["path_sound_picto"]["name"], '.')+1);
        $tmpSon = utf8_encode($_POST['nom_picto']).'.'.$extension2; 
       
        $picto = new Pictogram ($tmpId);
        $pictoDAO = new PictogramDAO ();
        $picto_img = $pictoDAO->findPictogram ($picto,$db);
        
        $img = $picto_img->getImage();
        $son = $picto_img->getSon();
        
        $file1 ="../sonPicto";
        unlink ($file1."/".$son);
        
        $file = "../imagesPicto" ;
        unlink ($file."/".$img);
        
	$pictogram = new Pictogram($tmpId, $tmpNom,null,$tmpTexte,$tmpimage,$tmpSon);
	$pictogramDAO = new PictogramDAO();
        
        $pictogramDAO->updatePictogram($pictogram, $db);
        $uploads_dir = "../imagesPicto/" . $tmpimage;
        
        $upload_dir = "../sonPicto/".$tmpSon;
        move_uploaded_file($_FILES['path_sound_picto']['tmp_name'],$upload_dir);

        move_uploaded_file($_FILES['path_img_picto']['tmp_name'], $uploads_dir);
        
        header('Location: ../partie_generateur/ens_gestion_picto.html');


       
?>